Skip to content

Tuan/homework 2#30

Open
tuanpham197 wants to merge 8 commits intoEngineerProOrg:scott/sample-gormfrom
tuanpham197:tuan/homework-2
Open

Tuan/homework 2#30
tuanpham197 wants to merge 8 commits intoEngineerProOrg:scott/sample-gormfrom
tuanpham197:tuan/homework-2

Conversation

@tuanpham197
Copy link

No description provided.

// lock
fmt.Println("lock")
err := rd.SetNX(rd.Context(), keyApiPing, id, 5*time.Second).Err()
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can retry till you can get the lock


fmt.Println("API /ping accessed")

err = rd.Close()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why need to close redis ?

}
}

if count == 2 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 call/60s mean if count =2 then still ok, count > 2 then rate limited

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and usually we should check > but not = , because what happen if 2 people call this api at the same time ? then you will get response = 3, even 4 5 6, then you allow them to call this api right ? which is wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants